{include="header"}

<script type="text/javascript">
   $(document).ready(function() {
      $("#b_nuevo_usuario").click(function(event) {
         event.preventDefault();
         $("#modal_nuevo_usuario").modal('show');
         document.f_nuevo_usuario.nnick.focus();
      });
   });
</script>

<div class="container-fluid" style="margin-top: 10px; margin-bottom: 5px;">
   <div class="row">
      <div class="col-sm-2">
         <div class="btn-group">
            <a class="btn btn-sm btn-default" href="{$fsc->url()}" title="Recargar la página">
               <span class="glyphicon glyphicon-refresh"></span>
            </a>
            {if condition="$fsc->page->is_default()"}
            <a class="btn btn-sm btn-default active" href="{$fsc->url()}&amp;default_page=FALSE" title="desmarcar como página de inicio">
               <span class="glyphicon glyphicon-home"></span>
            </a>
            {else}
            <a class="btn btn-sm btn-default" href="{$fsc->url()}&amp;default_page=TRUE" title="marcar como página de inicio">
               <span class="glyphicon glyphicon-home"></span>
            </a>
            {/if}
         </div>
      </div>
      <div class="col-sm-8 text-center">
         <h2 style="margin-top: 0px;">Usuarios</h2>
      </div>
      <div class="col-sm-2 text-right">
         <a id="b_nuevo_usuario" class="btn btn-sm btn-success" href="#">
            <span class="glyphicon glyphicon-plus"></span> &nbsp; Nuevo
         </a>
      </div>
   </div>
</div>

<div role="tabpanel">
   <ul class="nav nav-tabs" role="tablist">
      <li role="presentation" class="active">
         <a href="#home" aria-controls="home" role="tab" data-toggle="tab">Usuarios</a>
      </li>
      <li role="presentation">
         <a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Historial</a>
      </li>
   </ul>
   <div class="tab-content">
      <div role="tabpanel" class="tab-pane active" id="home">
         <div class="table-responsive">
            <table class="table table-hover">
               <thead>
                  <tr>
                     <th class="text-left">Nick</th>
                     <th class="text-left">Empleado</th>
                     <th class="text-center">Administrador</th>
                     <th class="text-left">IP</th>
                     <th class="text-left">Página de inicio</th>
                     <th class="text-left">Ejercicio</th>
                     <th class="text-right">Último login</th>
                  </tr>
               </thead>
               {loop="$fsc->user->all()"}
               <tr class="clickableRow" href="{$value->url()}">
                  <td><a href="{$value->url()}">{$value->nick}</a></td>
                  <td>{$value->get_agente_fullname()}</td>
                  <td class="text-center">
                     {if condition="$value->admin"}<span class="glyphicon glyphicon-ok"></span>{/if}
                  </td>
                  <td>{$value->last_ip}</td>
                  <td>{$value->fs_page}</td>
                  <td>{$value->codejercicio}</td>
                  <td class="text-right">{$value->show_last_login()}</td>
               </tr>
               {/loop}
            </table>
         </div>
      </div>
      <div role="tabpanel" class="tab-pane" id="profile">
         <div class="table-responsive">
            <table class="table table-hover">
               <thead>
                  <tr>
                     <th class="text-left">Usuario</th>
                     <th class="text-left">Detalle</th>
                     <th class="text-left">IP</th>
                     <th class="text-right">Fecha</th>
                  </tr>
               </thead>
               {loop="$fsc->historial"}
               <tr{if condition="$value->alerta"} class="bg-danger"{/if}>
                  <td><a href="index.php?page=admin_user&snick={$value->usuario}">{$value->usuario}</a></td>
                  <td>{$value->detalle}</td>
                  <td>{$value->ip}</td>
                  <td class="text-right">{$value->fecha}</td>
               </tr>
               {/loop}
            </table>
         </div>
      </div>
   </div>
</div>

<div class="modal" id="modal_nuevo_usuario">
   <div class="modal-dialog">
      <div class="modal-content">
         <form name="f_nuevo_usuario" class="form" role="form" action="{$fsc->page->url()}" method="post">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
               <h4 class="modal-title">Nuevo usuario</h4>
            </div>
            <div class="modal-body">
               <div class="form-group">
                  Nick:
                  <input class="form-control" type="text" name="nnick" autocomplete="off"/>
               </div>
               <div class="form-group">
                  Contraseña:
                  <input class="form-control" type="password" name="npassword"/>
               </div>
               <div class="form-group">
                  <label>
                     <input type="checkbox" name="nadmin" value="TRUE"/>
                     Administrador
                  </label>
               </div>
               <div class="form-group">
                  <a target="_blank" href="{$fsc->agente->url()}">Empleado</a>:
                  <select name="ncodagente" class="form-control">
                     <option value="">Ninguno</option>
                     {loop="$fsc->agente->all()"}
                     <option value="{$value->codagente}">{$value->get_fullname()}</option>
                     {/loop}
                  </select>
               </div>
            </div>
            <div class="modal-footer">
               <button class="btn btn-sm btn-primary" type="submit" onclick="this.disabled=true;this.form.submit();">
                  <span class="glyphicon glyphicon-floppy-disk"></span> &nbsp; Guardar
               </button>
            </div>
         </form>
      </div>
   </div>
</div>

{include="footer"}